
local wenxin = fk.CreateSkill {
  name = "lingling__wenxin",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__wenxin"] = "问心",
  [":lingling__wenxin"] = "锁定技，回合结束时，你摸三张牌，然后展示所有手牌，将体力值调整至与其中的<font color='red'>♥</font>牌数相同，"..
  "溢出则你失去1点体力。",
}

wenxin:addEffect(fk.TurnEnd, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(wenxin.name)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:drawCards(3, wenxin.name)
    if player.dead then return end
    local cards = table.simpleClone(player:getCardIds("h"))
    local n = #table.filter(cards, function (id)
      return Fk:getCardById(id).suit == Card.Heart
    end)
    if #cards > 0 then
      player:showCards(cards)
      if player.dead then return end
    end
    if player.hp > n then
      room:loseHp(player, player.hp - n, wenxin.name)
    elseif player.hp < n then
      local yes = n > player.maxHp
      room:recover{
        who = player,
        num = n - player.hp,
        recoverBy = player,
        skillName = wenxin.name,
      }
      if yes and not player.dead then
        room:loseHp(player, 1, wenxin.name)
      end
    end
  end,
})

return wenxin
